package com.qh.common.task;

import com.qh.oa.domain.Response;
import com.qh.pay.api.constenum.OutChannel;
import com.qh.pay.domain.PayQrConfigDO;
import com.qh.pay.service.PayHandlerService;
import com.qh.pay.service.PayQrConfigService;
import com.qh.redis.service.RedisUtil;
import com.qh.sms.service.SMSUtils;
import org.jboss.logging.Param;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class QrConfigTask implements Job {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TOneOrderClearTask.class);


    @Autowired
    private PayQrConfigService payQrConfigService;


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        HashMap<String, Object> hashMaps = new HashMap<>();
        hashMaps.put("outChannel", OutChannel.ali.name());
        hashMaps.put("useStatus", 1);
        hashMaps.put("payStatus", "0");
        List<PayQrConfigDO> payQrConfigDOS = payQrConfigService.list(hashMaps);
        for (PayQrConfigDO payQrConfigDO : payQrConfigDOS) {
            if (payQrConfigDO.getEndDate().isBefore(LocalDateTime.now())) {
                payQrConfigService.updatePayState("2",payQrConfigDO.getAccountNo(), payQrConfigDO.getOutChannel());
                RedisUtil.updateMonAmountNum(payQrConfigDO.getOutChannel(), String.valueOf(payQrConfigDO.getMoney()),
                        false);
            }

        }


    }


}
